/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ejb;

import java.io.CharArrayWriter;
import java.io.Reader;
import java.io.StringReader;
import javax.ejb.Stateless;
import javax.servlet.FilterConfig;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

@Stateless
public class XSLT { 

	TransformerFactory transformerFactory = TransformerFactory.newInstance();
	FilterConfig filterConfig = null;

	public String transform(String mXml, String mXSL) {

                Source styleSource = new StreamSource((Reader) new StringReader(mXSL));

		StringReader sr = new StringReader(mXml);
		Source xmlSource = new StreamSource((Reader)sr);

		// Ok... Transform the xml:
		try {
			Transformer transformer = transformerFactory.newTransformer(styleSource);
			CharArrayWriter caw = new CharArrayWriter();
			StreamResult result = new StreamResult(caw);
			transformer.transform(xmlSource, result);

			return caw.toString();
                        
		} catch (Exception ex) {
			return ex.getMessage();
		}

	}
}
